<!DOCTYPE html>

<html lang="zh-Hans">
  <head>
    <meta charset="utf-8" />
    <meta name="author" content="rogepi" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="/vue.global.js"></script>
    <title>7-todo-list-app</title>
  </head>

  <body>
    <div id="todo-list-app">
      <ol>
        <!-- 创建一个 todo-item 组件实例 -->
        <!--
      现在我们为每个 todo-item 提供 todo 对象
      todo 对象是变量，即其内容可以是动态的。
      我们也需要为每个组件提供一个“key”
    -->
        <todo-item
          v-for="item in groceryList"
          v-bind:todo="item"
          v-bind:key="item.id"
        ></todo-item>
      </ol>
    </div>
    <script>
      const TodoList = {
        data() {
          return {
            groceryList: [
              { id: 0, text: 'Vegetables' },
              { id: 1, text: 'Cheese' },
              { id: 2, text: 'Whatever else humans are supposed to eat' },
            ],
          };
        },
      };
      // 创建 Vue 应用
      const app = Vue.createApp(TodoList);

      // 定义名为 todo-item 的新组件
      app.component('todo-item', {
        props: ['todo'],
        template: `<li>{{todo.text}}</li>`,
      });

      // 挂载 Vue 应用
      app.mount('#todo-list-app');
    </script>
  </body>
</html>
